package com.imoblife.brainwavestus.listener;

import java.util.ArrayList;

import com.imoblife.brainwavestus.GroupCommonProductActivity;
import com.imoblife.brainwavestus.ProductDetailActivity;
import com.imoblife.brainwavestus.UserProductActivity;
import com.imoblife.brainwavestus.model.Constant;
import com.imoblife.brainwavestus.product.Product;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class OnProductItemClickListener implements OnItemClickListener{
	
	private Context mCtx;
	private ArrayList<Product> mDatas;
	private int source;
	
	public OnProductItemClickListener(Context ctx,
			ArrayList<Product> data,
			int productSource) {
		
		mCtx = ctx;
		mDatas = data;
		source = productSource;
	}
	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		
		Product product = mDatas.get(position);
		Intent intent = null;
		
		switch(source) {
		
		case Constant.SOURCE_FROM_LOCAL:
			intent = new Intent(mCtx, UserProductActivity.class);
			break;
		case Constant.SOURCE_FROM_STORE:
			intent = new Intent(mCtx, ProductDetailActivity.class);
			break;
		default:
			intent = new Intent(mCtx, ProductDetailActivity.class);
			break;
		}

		intent.putExtra(Constant.PRODUCT_ID, 
				product.getProductInfo().getName());

		mCtx.startActivity(intent);
	}

}
